home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part2 / 14817 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.2 KB

  1. Path: news-relay.eworld.com!zdc!zippo!drn
  2. From: Clarence Chiang
  3. Newsgroups: comp.lang.c++
  4. Subject: Re: delete or delete [] ?
  5. Date: 1 Apr 1996 12:26:27 -0800
  6. Organization: Zippo
  7. Sender: http@doc.zippo.com
  8. Message-ID: <4jpe5j$3vo@doc.zippo.com>
  9. NNTP-Posting-Host: doorstop.spiderisland.com
  10.  
  11. In article <4jp7n7$f8k@mcmail.CIS.McMaster.CA>, g9326161@mcmail.cis.McMaster.CA says...
  12. >
  13. >In almost all of C++ literatures, "delete aa" should be used iff aa is not an 
  14. >array and "delete [] aa" should be used iff aa is an array. In following case,
  15. >what should I use?
  16. >
  17. >typedef int int10[10];
  18. >int* aa=new int10; // array of 10 integers.
  19. >
  20. >delete aa;
  21. >
  22. >or 
  23. >
  24. >delete [] aa;
  25. >
  26. >For gcc (v2.6), it seems that both work. Which is the standard one?
  27. >
  28. >Thanks!
  29. >
  30. >Hong Shen
  31.  
  32. Actually it is quite simple, if the object is not an array, use delete; if it
  33. is an array use delete [].
  34.  
  35. You example works, and so will any example, is because of the way deallocating
  36. a memory location occupy by an object and an array is just the same. The difference
  37. between delete and delete[] is that delete [] will call the destructor for each
  38. item in the array. Because int doesn't have a destructor, so it doesn't matter
  39. if you use delete or delete[].
  40.  
  41. Clarence Chiang
  42. Spider Island Software
  43.  
  44.